<?php
/**
 * Created by PhpStorm.
 * User: zjw
 * Date: 2018/3/29
 * Time: 上午11:40
 */

namespace backend\models;

use common\models\BindPhone;
use common\models\CouponCategory;
use common\models\User;
use yii\data\ActiveDataProvider;
use yii\db\ActiveQuery;

/**
 *
 * @property ActiveQuery $query
 */
class UserSearch extends User
{
    public $phone;
    public $query;

    public function rules()
    {
        return [
            [['phone'], 'string']
        ];
    }

    public function search($params)
    {
        $this->query = User::find();
        $dataProvider = new ActiveDataProvider([
            'query' => $this->query
        ]);
        if (!$this->load($params)) {
            return $dataProvider;
        }
        if (isset($this->phone) && $this->phone !== '') {
            $this->setPhone();
        }
        return $dataProvider;
    }


    public function setPhone()
    {
        $this->query->andWhere(['phone' => $this->phone]);
    }
}
